/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.common.constant.enums;

import com.google.common.collect.Maps;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 人脸识别-活体控制
 *
 * @author duanlikao
 * @created 2020/12/30
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum FaceLivenessControlEnum {

    /**
     * 不进行控制
     */
    FACE_LIVENESS_CONTROL_TYPE_NONE(0, "NONE"),
    /**
     * 较低的活体要求(高通过率 低攻击拒绝率)
     */
    FACE_LIVENESS_CONTROL_TYPE_LOW(1, "LOW"),
    /**
     * 一般的活体要求(平衡的攻击拒绝率, 通过率)
     */
    FACE_LIVENESS_CONTROL_TYPE_NORMAL(2, "NORMAL"),

    /**
     * 较高的活体要求(高攻击拒绝率 低通过率)
     */
    FACE_LIVENESS_CONTROL_TYPE_HIGH(3, "HIGH");

    private  Integer code;
    private  String msg;

    private static Map <Integer, FaceLivenessControlEnum> codeMap = Maps.newHashMap();

    public Integer getCode() {
        return this.code;
    }

    public String getDesc() {
        return this.msg;
    }

    public static String getMsg(Integer code) {
        return codeMap.containsKey(code) ? codeMap.get(code).getDesc() : StringUtils.EMPTY;
    }

    public static boolean isValid(Integer code) {
        return codeMap.containsKey(code);
    }

    static {
        for (FaceLivenessControlEnum status : FaceLivenessControlEnum.values()) {
            codeMap.put(status.getCode(), status);
        }
    }

    public static FaceLivenessControlEnum getFaceLivenessControlEnumByVal(Integer code) {
        return Arrays.stream(FaceLivenessControlEnum.values())
                .collect(Collectors.toMap(FaceLivenessControlEnum::getCode, value -> value, (k1, k2) -> k2)).get(code);
    }
}